package com.hw.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * 用户表
 * t_user
 *
 * @author
 */
@Getter
@Setter
@ToString
public class User implements Serializable, UserDetails {
    /**
     * 用户id
     */
    private Integer id;

    /**
     * 用户名称
     */
    private String username;

    /**
     * 用户密码
     */
    private String password;

    /**
     * 用户权限集合
     */
    private List<Role> userRoles;

    /**
     * 角色菜单集合
     */
    private List<Menu> roleMenus;

    private Collection<? extends GrantedAuthority> authorities;

    public User() {
    }

    public User(String username, String password, List<Menu> roleMenus, Collection<? extends GrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.roleMenus = roleMenus;
        this.authorities = authorities;
    }

    private static final long serialVersionUID = 1L;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }


    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}